package com.school.gift.controller.admin;

import com.github.pagehelper.PageInfo;
import com.school.gift.domain.SysConfig;
import com.school.gift.service.SysConfigService;
import com.school.support.base.AdminBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import zhibi.common.support.base.Page;
import zhibi.common.support.mybatis.example.Example;
import zhibi.common.support.mybatis.example.ExampleType;
import zhibi.common.support.mybatis.example.ExampleUtil;

/**
 * Created by 执笔 on 2017/3/17.
 */
@Controller
@RequestMapping("/admin/config")
public class MSysConfigController extends AdminBaseController {

    @Autowired
    private SysConfigService sysConfigService;

    @RequestMapping("list")
    public String  list(Model model, Page page, SysConfig sysConfig){
        Example example = ExampleUtil.getInstance()
                .addParam("name", sysConfig.getName(), ExampleType.Operation.LIKE)
                .getExample();
        PageInfo<SysConfig> pageInfo = sysConfigService.selectByExample(example, page);
        setModelAttribute(model,pageInfo);
        return "admin/config/list";
    }

    @RequestMapping("detail/{id}")
    public String detail(@PathVariable Integer id,Model model){
        SysConfig sysConfig = sysConfigService.selectByPK(id);
        model.addAttribute(sysConfig);
        return "admin/config/detail";
    }

    @RequestMapping("update")
    public String update(SysConfig sysConfig){
        sysConfigService.updateByIdSelective(sysConfig);
        return redirect("detail/"+sysConfig.getId());
    }
}
